package com.beiyou.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import com.beiyou.dao.PersonDao;
import com.beiyou.dao.TrackDao;
import com.beiyou.dao.VenueDao;
import com.beiyou.model.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/yunji-api/track")
public class TrackController {

    @Autowired
    private TrackDao trackDao;
    @Autowired
    private VenueDao venueDao;

    @PostMapping("/insert")

    //返回人员健康状态码
    public LogTrackOk insert(@RequestBody Track track){
      //省略校验
        trackDao.insert(track);
        LogTrackOk logTrackOk = new LogTrackOk();
        int status = RandomUtil.randomInt(1, 4); //1 代表绿码，2代表黄码码，  3 代表红码 需要调政府提供Api，
        switch (status){
            case 3:
                logTrackOk.setColor("#FF0000");
                break;
            case 2:
                logTrackOk.setColor("#FFD700");
                break;
            default:
                logTrackOk.setColor("#32CD32");
                break;
        }
        //设置扫码时间
        logTrackOk.setLogTime(DateUtil.now());
        //获取场所的名称
        VenueQuery query = new VenueQuery();
        query.setId(track.getVenueId());
        List<Venue> venueLst  = venueDao.select(query);
        Venue venue = venueLst.get(0);
        logTrackOk.setVenueName(venue.getName());


        return logTrackOk;


    }

    @PostMapping("/select")
    public  List<TrackInfo> select(@RequestBody TrackQuery query){
        //省略校验
        return    trackDao.select(query);
    }

    @PostMapping("/heatmap/select")
    public  List<TrackHeatMapInfo> heatMapSelect(@RequestBody TrackQuery query){
        //省略校验
        return    trackDao.selectHeatMap(query);
    }

}
